home *** CD-ROM | disk | FTP | other *** search
- Path: zetnet.co.uk!demon!stsdaveb.demon.co.uk
- From: dave@stsdaveb.demon.co.uk (Dave Thornton)
- Newsgroups: comp.lang.c
- Subject: Re: Accessing UNIX environment variables with C
- Date: Fri, 26 Jan 1996 15:28:08 GMT
- Organization: Severn Trent Systems
- Message-ID: <3108f268.14258749@news.demon.co.uk>
- References: <4eaqt5$f23@zippy.cais.net>
- NNTP-Posting-Host: stsdaveb.demon.co.uk
- X-NNTP-Posting-Host: stsdaveb.demon.co.uk
- X-Newsreader: Forte Agent .99c/16.141
-
- On 26 Jan 1996 15:10:29 GMT, usaid@cais.cais.com (USAID) wrote:
-
- >Can someone tell me how to use a UNIX environment variable in C? The
- >equivalent statement in Perl is the %ENV{VARNAME} statement, where
- >VARNAME is the environment variable.
- >
- >Thanks for your help.
- >
- >Jed Prentice
-
-
- I think its the standard ANSI C function getenv();
-
- /* Example for getenv */
-
- #include <stdio.h>
- #include <stdlib.h>
-
- void main ()
- {
- char *path;
-
- path = getenv ("PATH");
- if (path == NULL)
- fprintf (stderr, "No PATH set\n");
- else
- printf ("PATH=%s\n", path);
- }
-
- Its a long time since I worked on Unix machines but I think this is
- how its done..
-
- Regards
-
- -------------------------------------------------------------------------------
- | Dave Thornton | email dave@stsdaveb.demon.co.uk |
- | Staffs, England | |
- -------------------------------------------------------------------------------
-